<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 表格展示区域 -->
    <el-table :data="rightsInfoList" border style="width: 100%" highlight-current-row>
      <el-table-column type="index"></el-table-column>
      <el-table-column prop="authName" label="权限名称"></el-table-column>
      <el-table-column prop="path" label="路径"></el-table-column>
      <el-table-column prop="level" label="层级" width="160">
        <template slot-scope="scope">{{scope.row.level | levelFormat}}</template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
// 引入请求接口模块
import { getAllRightList } from '@/api/right_api.js'
export default {
  data () {
    return {
      rightsInfoList: [
        {
          id: '',
          authName: '',
          level: '',
          pid: '',
          path: ''
        }
      ]
    }
  },
  mounted () {
    getAllRightList('list')
      .then(res => {
        // console.log(res)
        if (res.data.meta.status === 200) {
          this.rightsInfoList = res.data.data
          // console.log(this.rightsInfoList)
        } else {
          this.$message({
            type: 'error',
            message: '获取数据失败'
          })
        }
      })
      .catch(err => {
        console.log(err)
      })
  },
  //   通过filters添加当前组件的局部过滤器
  filters: {
    levelFormat: level => {
      if (level === '0') {
        return '一级'
      } else if (level === '1') {
        return '二级'
      } else if (level === '2') {
        return '三级'
      }
    }
  }
}
</script>
<style lang="less" scoped>
</style>
